package com.stardust.service;

import com.stardust.mapper.QuestionMapper;
import com.stardust.pojo.Questions;
import com.stardust.pojo.ResultControl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class QuestionServiceImpl implements QuestionService{

    @Autowired
    private QuestionMapper questionMapper;
    @Override
    public ResultControl add(Questions questions) {
        questionMapper.insert(questions);
        return new ResultControl();
    }

    @Override
    public ResultControl delete(Integer id) {
        questionMapper.delete(id);
        return new ResultControl();
    }

    @Override
    public ResultControl update(Questions questions) {
        questionMapper.update(questions);
        return new ResultControl();
    }

    @Override
    public ResultControl query(String title, Integer page, Integer size) {
        if (null == page || page <1){
            page = 1;
        }
        if (null ==size || size <1){
            size = 10;
        }
        int skip = (page - 1)*size;
        List<Questions> questions = questionMapper.select(title,skip,size);
        ResultControl resultControl = new ResultControl();
        resultControl.data.put("value",questions);
        return resultControl;
    }

    @Override
    public ResultControl searchByID(Integer id) {
        questionMapper.serach(id);
        return new ResultControl();
    }
}
